package com.lhn;

import com.lhn.dao.BookDao;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/**
 * @author lhn
 * @date 2024-08-19 12:32
 */

public class AppForBeanFactory {
    public static void main(String[] args) {
        Resource resource = new ClassPathResource("application.xml");
        BeanFactory bf = new XmlBeanFactory(resource);
        BookDao bookDao = (BookDao) bf.getBean("bookDao");
        bookDao.save();

        //BeanFactory在加载玩配置文件后，没有对象实例化，只有第一次获取对象的时候才会实例化对象

        //ApplicationContext在加载完配置文件后，就会实例化对
        //象(在xml文件的bean中添加 lazy-init="true"可到达上述效果)
    }
}
